<div class="box box-solid">
    <div class="box-body table-responsive no-padding">
    <h2 style="text-align: center;">特殊地区 附加运费设置</h2>
    <?php if($admin_name == 'admin' || !array_key_exists('system/allshipfee', $sp['系统管理']) || (array_key_exists('system/allshipfee', $sp['系统管理'])&& in_array('system/allshipfee', $user_sp['sp']))): ?>
        <div class="form-group">
            <label>
            将所有地区运费统一更新为:
            <input id="all_ship_fee" class="form-control"/>
            <span class='btn  btn-success all_fee'>更新</span>
                
            </label>
        </div>
    <?php endif; ?>
        <div class="box-body">
                <div class="form-group">
                    <label>地区列表:</label>
                    
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>名称</th>
                            <th>运费</th>
                             <th>操作</th> 
                        </tr>
                            <?php if(!empty($result )): ?>
                                <?php foreach ($result as $key => $value) :?>
                                <tr>
                                    <td><?php echo $value['sid']; ?></td>
                                    <td><?php echo $value['province'] ?></td>
                                    <td><input class='ship_fee' value="<?php echo $value['ship_fee'] ?>" /></td>
                                    <td>
                                     <?php if($admin_name == 'admin' || !array_key_exists('system/saveshipfee', $sp['系统管理']) || (array_key_exists('system/saveshipfee', $sp['系统管理'])&& in_array('system/saveshipfee', $user_sp['sp']))): ?>
                                        <input type='hidden' class='sid' value="<?php echo $value['sid'] ?>" />
                                        <a href="#" class='save_fee'>保存</a>
                                    <?php endif; ?>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tr>
                    </table>
                </div>
            </div>
    </div>
</div>
<style type="text/css">
    .ship_fee{
        border:0;
        outline: none;
    }
</style>
<script type="text/javascript">
    $(function(){
        $('.ship_fee').blur(function(){
            $(this).parent().parent().find('.save_fee').click();
        })
        $('.save_fee').click(function(){
            var province_id= $(this).parent().parent().find('.sid').val();
            var ship_fee= $(this).parent().parent().find('.ship_fee').val();
            $.ajax({
                type    : 'post',
                async   : true,
                url     : "<?php echo $this->createUrl('system/saveshipfee') ?>",
                data    : {province_id:province_id,ship_fee:ship_fee},
                dataType: 'json',
                success :function(data){
                    if (data!=-1&&data!=0) { 

                    }else{
                        alert('保存失败,请重试!');
                    }
                } ,
                error:function(){
                    alert('服务器忙,请稍后重试!');
                }
            });
        });

        $('.all_fee').click(function(){
            var ship_fee= $('#all_ship_fee').val();
            if (ship_fee =='' || isNaN(ship_fee)) {
                alert('请填写正确的运费!');
            } else {
                if(!confirm('确定需要将所有运费统一更新为:'+ship_fee+' ?')){
                    return false;
                }
                $.ajax({
                    type    : 'post',
                    async   : true,
                    url     : "<?php echo $this->createUrl('system/allshipfee') ?>",
                    data    : {ship_fee:ship_fee},
                    dataType: 'json',
                    success :function(data){
                        if (data!=-1&&data!=0) { 
                            $('.ship_fee').val(ship_fee);
                        }else{
                            alert('保存失败,请重试!');
                        }
                    } ,
                    error:function(){
                        alert('服务器忙,请稍后重试!');
                    }
                });
            }
        });
    });
</script>